<?php

/**
 * Category form.
 *
 * @package    www.furr.sk
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CategoryForm extends BaseCategoryForm
{
  public function configure()
  {
      $this->setWidgets(array(
      'id'                    => new sfWidgetFormInputHidden(),
      'parent'                => new sfWidgetFormInput(),
      'visible'               => new sfWidgetFormInputCheckbox(),
      'menu'                  => new sfWidgetFormInput(),
      'ord'                   => new sfWidgetFormInput(),
      'extern'                => new sfWidgetFormInputCheckbox(),
      //'category_list'         => new sfWidgetFormDoctrineChoiceMany(array('model' => 'Category')),
    ));

    $this->setValidators(array(
      'id'                    => new sfValidatorDoctrineChoice(array('model' => 'Category', 'column' => 'id', 'required' => false)),
      'parent'                => new sfValidatorInteger(array('required' => false)),
      'visible'               => new sfValidatorBoolean(array('required' => false)),
      'menu'                  => new sfValidatorInteger(array('required' => false)),
      'ord'                   => new sfValidatorInteger(array('required' => false)),
      'extern'                => new sfValidatorBoolean(array('required' => false)),
     // 'category_list'         => new sfValidatorDoctrineChoiceMany(array('model' => 'Category', 'required' => false)),
    ));
    $exlude = null;
    if (!$this->getObject()->isNew())
         $exlude = $this->getObject()->getId();
    $categories = Doctrine::getTable('Category')->getCategoriesCascadeFlat(null, null, false, $exlude);
    $categoryArray = array();
    $categoryArray[]='none';
    foreach ($categories as $category)
    {
         $categoryArray[ $category['category']->getId()] = str_pad('', 2 * $category['level'], '- ') . $category['category']->getTitle();
    }
    $this->widgetSchema['parent'] = new sfWidgetFormSelect(array('choices' => $categoryArray));
    $this->widgetSchema->setNameFormat('category[%s]');
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  }
}
